<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数据库管理</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script src="js/page.js"></script>
</head>

<body onload="initialize();">
<jsp:useBean id="database" class="DatabaseConnection.DatabaseConnection" />
<%
request.setCharacterEncoding("utf-8");
String host_address = request.getParameter("host_address");
String port_type = request.getParameter("port_type");
String host_port = request.getParameter("host_port");
String host_username = request.getParameter("host_username");
String host_password = request.getParameter("host_password");
String remember_setup = request.getParameter("remember_setup");
if (port_type.equals("default"))
	host_port = "3306";
database.initDatabase(host_address, host_port, host_username, host_password);
String sql_databases = "show databases;";
ResultSet resultset_databases = database.executeQuery(sql_databases);
if (resultset_databases != null)
{
	session.putValue("mysql_host_address",host_address);
	session.putValue("mysql_host_port",host_port);
	session.putValue("mysql_host_username",host_username);
	session.putValue("mysql_host_password",host_password);
	if (remember_setup != null && remember_setup.equals("remember"))
	{
		String remember_setup_string = host_address + "," + host_port + "," + host_username + "," + host_password;
		Cookie cookie_remember_setup = new Cookie("mysql_remember_setup", remember_setup_string);
		cookie_remember_setup.setMaxAge(60 * 60 * 24 * 30);
		response.addCookie(cookie_remember_setup);
	}
%>
<script type="text/javascript">
<!--
	window.alert("数据库服务器连接成功！");
	window.location.href = "databases.jsp";
//-->
</script>
<%
}
else
{
%>
<script type="text/javascript">
<!--
	window.alert("数据库服务器连接失败！");
	window.history.go(-1);
//-->
</script>
<%
}
if (resultset_databases != null)
	resultset_databases.close();
database.closeConnection();
%>
</body>
</html>